//
//  header.swift
//  WaiBaoYuan
//
//  Created by 赵佟越 on 17/5/10.
//  Copyright © 2017年 user. All rights reserved.
//

import Foundation
import UIKit
import SDWebImage
import SwiftyUserDefaults
import Moya
import Toast_Swift


let IS_IOS7 = (UIDevice.current.systemVersion as NSString).doubleValue >= 7.0
let IS_IOS8 = (UIDevice.current.systemVersion as NSString).doubleValue >= 8.0

//var kcolerMain = UIColor.init(getColor: "262626")


let kScreenHeight = UIScreen.main.bounds.size.height
let kScreenWidth = UIScreen.main.bounds.size.width

let _kScreenHeight = UIScreen.main.bounds.size.height/667
let _kScreenWidth = UIScreen.main.bounds.size.width/375

public let kiOSBase = 8.0
public let kOSGreaterOrEqualToiOS8 = ( (Double(UIDevice.current.systemVersion) ?? kiOSBase) > 8.0 ) ? true : false;
public let kOSGreaterOrEqualToiOS9 = ((Double(UIDevice.current.systemVersion) ?? kiOSBase) >= 9.0 ) ? true : false;
public let kOSGreaterOrEqualToiOS10 = ((Double(UIDevice.current.systemVersion) ?? kiOSBase) >= 10.0 ) ? true : false;
public let kOSGreaterOrEqualToiOS11 = ((Double(UIDevice.current.systemVersion) ?? kiOSBase) >= 11.0 ) ? true : false;



func printLog<T>(message: T,
              file: String = #file,
              method: String = #function,
              line: Int = #line)
{
    #if DEBUG
        print("\((file as NSString).lastPathComponent)[\(line)], \(method): \(message)")
    #endif
}
// MARK: - 颜色转换
//extension UIColor {
//    
//    /// 用十六进制颜色创建UIColor
//    ///
//    /// - Parameter hexColor: 十六进制颜色 (0F0F0F)
//    convenience init(getColor: String) {
//        // 存储转换后的数值
//        var red:UInt32 = 0, green:UInt32 = 0, blue:UInt32 = 0
//        
//        // 分别转换进行转换
//        Scanner(string: getColor[0..<2]).scanHexInt32(&red)
//        
//        Scanner(string: getColor[2..<4]).scanHexInt32(&green)
//        
//        Scanner(string: getColor[4..<6]).scanHexInt32(&blue)
//        
//        self.init(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: 1.0)
//    }
//}

extension String{
    
    func md5(inString: String) -> String! {
        let str = inString.cString(using: String.Encoding.utf8)
        let strLen = CUnsignedInt(inString.lengthOfBytes(using: String.Encoding.utf8))
        let digestLen = Int(CC_MD5_DIGEST_LENGTH)
        let result = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLen)
        CC_MD5(str!, strLen, result)
        let hash = NSMutableString()
        for i in 0..<digestLen {
            hash.appendFormat("%02x", result[i])
        }
        result.deallocate()
        return String(format: hash as String)
    }
}


//extension String {
//    
//    /// String使用下标截取字符串
//    /// 例: "示例字符串"[0..<2] 结果是 "示例"
//    subscript (r: Range<Int>) -> String {
//        get {
//            let startIndex = self.index(self.startIndex, offsetBy: r.lowerBound)
//            let endIndex = self.index(self.startIndex, offsetBy: r.upperBound)
//            
//            return self[startIndex..<endIndex]
//        }
//    }
//}
